package com.sch.example.view;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.sch.example.R;


/**
 * 时间Window
 */
public class TimeWindow extends PopupWindow {

    // 通用
    private Context mContext;

    private WheelView_New mLeftWheel;
    private WheelView_New mRightWheel;


    private TextView mTvRe,mTvOK;
    private String[] mArrTime;



    /**
     * 初始化
     */
    public TimeWindow(Activity mContext) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.window_time, null);

        this.mContext = mContext;
        this.setContentView(view);                                 // 设置SelectPicPopupWindow的View
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);       // 设置SelectPicPopupWindow弹出窗体的高
        this.setAnimationStyle(R.style.AnimBottom);                // 设置SelectPicPopupWindow弹出窗体动画效果
        this.setBackgroundDrawable(new ColorDrawable(0xb0000000)); // 设置SelectPicPopupWindow弹出窗体的背景

        this.setTouchable(true);                                   // 这个控制PopupWindow内部控件的点击事件
        this.setFocusable(true);
        this.setOutsideTouchable(true);

        initWheel(view);
    }


    /**
     * 确定键/重置 监听
     */
    public void setOnBtnListener(View.OnClickListener listener){
        mTvRe.setOnClickListener(listener);
        mTvOK.setOnClickListener(listener);
    }



    /**
     * 初始化
     */
    private void initWheel(View view) {
        mArrTime = mContext.getResources().getStringArray(R.array.times);

        mTvRe = view.findViewById(R.id.tv_re);
        mTvOK = view.findViewById(R.id.tv_ok);

        mLeftWheel = view.findViewById(R.id.select_time_wheel_left);
        mRightWheel = view.findViewById(R.id.select_time_wheel_right);
        mLeftWheel.setWheelStyle(WheelStyle_New.STYLE_TIME,mArrTime);
        mRightWheel.setWheelStyle(WheelStyle_New.STYLE_TIME,mArrTime);
    }


    /**
     * 设置初始值
     */
    public void setInitValue(int indexLeft,int indexRight){
        mLeftWheel.setCurrentItem(indexLeft);
        mRightWheel.setCurrentItem(indexRight);
    }

    /**
     * 获取 左侧时间
     */
    public String getTimeLeft() {
        return mArrTime[mLeftWheel.getCurrentItem()];
    }

    /**
     * 获得 右侧时间
     */
    public String getTimeRight() {
        return mArrTime[mRightWheel.getCurrentItem()];
    }
}
